package com.bhs.sansong.ui.setting;

import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bhs.sansong.R;
import com.bhs.sansong.adapter.SatisfyAdapter;
import com.bhs.sansong.base.BaseActivity;
import com.bhs.sansong.base.BaseBean;
import com.bhs.sansong.bean.CloseAccountBean;
import com.bhs.sansong.net.NetCallBack;
import com.bhs.sansong.utils.ToastUtil;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * 注销账号
 */
public class CloseAccountActivity extends BaseActivity implements View.OnClickListener, NetCallBack {

    private RecyclerView mRvList;
    private Button mBtnSubmit;
    private SatisfyAdapter mAdapter;

    @Override
    public int initLayout() {
        return R.layout.activity_close_account;
    }

    @Override
    public void initView() {

        TextView mTvTitle = findViewById(R.id.tv_title);
        mTvTitle.setText("申请注销");
        mRvList = findViewById(R.id.rv_list);
        mBtnSubmit = findViewById(R.id.btn_submit);
        mBtnSubmit.setOnClickListener(this);
    }

    @Override
    public void initData() {

        List<CloseAccountBean> mList=new ArrayList<>();
        mList.add(new CloseAccountBean("账户余额","您的账户余额已清零",true));
        mList.add(new CloseAccountBean("应收应付","您的账单已结算完成",true));
        mList.add(new CloseAccountBean("订单信息","您的订单均已完成",true));
        mAdapter = new SatisfyAdapter(mList);
        mRvList.setAdapter(mAdapter);
        mRvList.setLayoutManager(new LinearLayoutManager(mContext));
        verify();
    }

    private void verify() {
        boolean verify=true;
        mBtnSubmit.setEnabled(verify);
        mBtnSubmit.setBackgroundColor(verify ? Color.parseColor("#485EF4") : Color.parseColor("#7F485EF4"));
    }

    @Override
    public void onClick(View view) {
        networkRequest(netApi.logoff(),this);
    }

    @Override
    public void onResponse(int requestCode, String json, Response<ResponseBody> response) throws Exception {
        BaseBean bean=new Gson().fromJson(json,BaseBean.class);
        ToastUtil.show(bean.getMsg());
        if(bean.isStatus()){
            finish();
        }
    }

    @Override
    public void onFailure(int requestCode) {

    }
}